home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 6
/
MacMania 6.toast
/
/
Tools&Utilities
/
EnterAct Stuff
/
Drag_on Modules
/
hAWK programs
/
$ClipOldCDeclToNew
< prev
next >
Wrap
Text File
|
1995-01-23
|
3KB
|
90 lines
# $OldCtoNewDaemon : convert old-style C function "lead in"
# to new style. This is an example of a "clip daemon", also
# known as the "magic clipboard".
# Use: call up hAWK, and run this program: it will continue
# to run concurrently as you return to your editor, monitoring
# the clipboard all the while. When you Copy an old-style
# C function declaration in your editor, this program will
# use getclip() to retrieve it, generate a new-style declaration,
# and then give the new one back to your editor with putclip().
# A flash of the menu bar indicates success, at which point
# you can paste the new decl over the old one.
# IMPORTANT! When you're done with this program (or any similar
# program that never terminates on its own),
# PRESS <Command><period> in your editor to stop it.
# (The stderr window will appear as confirmation that this program
# has stopped -- you can ignore it otherwise.)
# Sequence in brief is Copy old style, flash, Paste new style.
# When done changing declaration, press <Command><period>.
# This program needs no input, since it runs all the time
# and looks to your clipboard for input. The only output it
# generates is to your clipboard, also.
# This is an example only, from which you should be able to
# derive specific "magic clipboard" programs to suit your needs.
# Here the old-style declaration must follow a rigid format:
# <space>return-type
# function-name(parameters)
# <tab>param-type param1;
# ...
# <tab>param-type last_param;
BEGIN {
while (1) # run until <Command><period>...
{
# see if clipboard has changed
if ((newClip = getclip(32)) != oldClip)
{
oldClip = newClip;
# a leading space is used as the trigger
if (substr(newClip, 1,1) == " ")
ClipFixProto()
}
}
}
function ClipFixProto( elClip, out, numLines, lines, i)
{
elClip = getclip(); # gets calling editor's private clip
# split clip up into separate lines
numLines = split(elClip, lines, "\r");
# with "split", the last line will be empty if the last
# character copied was a return.
if (lines[numLines] == "")
--numLines;
out = "";
out = "pascal" lines[1]; #get return type, prepend "pascal"
sub(/\(.*\)/, "", lines[2]); #clear params after the name
out = out " " lines[2]; #get the function name
if (numLines >= 3)
sub(/[ \t]/, "", lines[3]);
for (i = 3; i <= numLines; ++i)
{
sub(/;/, ",", lines[i]); # change semicolons to commas
}
out = out "\r";
if (numLines >= 3)
{
# small bug, must be only one comma on last line of parms
sub(/,/, "", lines[numLines]); #delete last comma
# get the (new-style) parameters
if (numLines == 3)
out = out "\t(" lines[3] ")\r"
else if (numLines > 3)
out = out "\t(" lines[3] "\r"
for (i = 4; i < numLines; ++i)
out = out lines[i] "\r";
if (numLines > 3)
out = out lines[numLines] ")\r"
}
# send the result back to the calling editor's clip
putclip(out);
## test only
##print out;
# flash menu bar to signal something happened
beep(0);
}